package cn.czh0123.controller;

import cn.czh0123.domain.Comment;
import cn.czh0123.query.CommentQuery;
import cn.czh0123.service.ICommentService;
import cn.czh0123.utils.ResultWrapper;
import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
* 评论控制层
*/
@RestController
@RequestMapping("comments")
public class CommentController {

    @Resource
    private ICommentService commentService;

    @GetMapping("/getComments")
    public ResultWrapper<IPage<Comment>> getComments(CommentQuery qo){
        return ResultWrapper.success(commentService.queryPage(qo));
    }

    @SaCheckLogin
    @DeleteMapping("/delete")
    public ResultWrapper<?> delete(Long id){
        commentService.removeById(id);
        return ResultWrapper.success();
    }

    @SaCheckLogin
    @PostMapping("/add")
    public ResultWrapper<?> add(@Valid @RequestBody Comment comment){
        return ResultWrapper.success(commentService.saveComment(comment));
    }

}
